/*
 *	main.cpp
 *
 *	search.exe
 *
 *	Audio Finger Print project
 */

#define _CRT_SECURE_NO_WARNINGS

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "..\sglib\spectrogram.h"

#define FRAME_N	256

int main(const int argc, const char* argv[])
{
	FILE* finSubstring;
	__int64 sizeSubstring;
	__int32* bufSubstring;

	if(argc < 2)
	{
		printf(
			"not enough arguments\n"
			);
		exit(1);
	}

	if(NULL == (finSubstring = fopen(argv[1], "rb")))
	{
		printf("can't open %s file\n", argv[1]);
		exit(1);
	}

	fseek(finSubstring, 0, SEEK_END);
	sizeSubstring = ftell(finSubstring)/sizeof(__int32);
	fseek(finSubstring, 0, SEEK_SET);

	if(NULL == (bufSubstring = (__int32*)malloc(sizeSubstring*sizeof(__int32))))
	{
		printf("[sizeSubstring] memory allocation error\n");
		exit(1);
	}

	if(sizeSubstring != fread(bufSubstring, sizeof(__int32), sizeSubstring, finSubstring))
	{
		printf("can't read file\n");
		exit(1);
	}

	SG_Search(bufSubstring, FRAME_N);
//	SG_Search(bufSubstring, sizeSubstring);
}
